/**数据验证*/
var RoomInfoValidator = function() {  
    var handleSubmit = function() { 
        $('.form-horizontal').validate({  
            errorElement : 'span',  
            errorClass : 'help-block',  
            focusInvalid : false,  
            rules : {  
            	"coveredarea" : {  
                    required : true ,
                    number : true
                },  
                "ucarea" : {  
                    required : true,
                    number : true
                },
                "heatingarea"  :{
                	required : true,
                	number : true
                },
                "filearea"  :{
                	required : true,
                	number : true
                }
            },  
            messages : {  
            	"coveredarea"  : {  
                    required : "请输入建筑面积.",
                    number : "请输入数字"
                },  
                "ucarea" : {  
                    required : "请输入套内面积.",
                    number : "请输入数字"
                },
                "heatingarea"  :{
                	required : "请输入采暖面积.",
                	number : "请输入数字"
                },
                "filearea"  :{
                	required : "请输入采暖片大小.",
                	number : "请输入数字"
                }
            },  
  
            highlight : function(element) { 
                $(element).closest('.control-group').addClass('error');  
            },  
  
            success : function(label) { 
                label.closest('.control-group').removeClass('error');  
                label.remove();
            },  
  
            errorPlacement : function(error, element) {  
            	element.parent('div').append(error);  
            },  
  
            submitHandler : function(form) {
                form.submit();
            }  
        });  
  
        $('.form-horizontal input').keypress(function(e) {  
            if (e.which == 13) {  
                if ($('.form-horizontal').validate().form()) {  
                    $('.form-horizontal').submit();  
                }  
                return false;  
            }  
        });  
    }  
    return {  
        init : function() { 
            handleSubmit(); 
        }  
    };  
  
}(); 


/**保存数据*/
function saveRoomInfo(){
	$('#myModal').modal('show');
	var icode=$("#icode").val();
	var rid=$("#rid").val();
	var hcode=$("#hcode").val();
	var coveredarea=$("#coveredarea").val();
	var ucarea=$("#ucarea").val();
	var heatingarea=$("#heatingarea").val();
	var filearea=$("#filearea").val();
	var ctime=$("#ctime").val();
	var cost=$("#cost").val();
	var kitchen=$("input[@type=radio][name=kitchen][checked]").val();
	var toilet=$("input[@type=radio][name=toilet][checked]").val();
	var content=$("#ricontent").val();
	$.post("../base/save_RoomInfo.action",{"ri.icode":icode,"ri.houseType.hcode":hcode,"ri.coveredarea":coveredarea,
		"ri.ucarea":ucarea,"ri.heatingarea":heatingarea,"ri.filearea":filearea,"ri.ctime":ctime,"ri.cost":cost,
		"ri.kitchen":kitchen,"ri.toilet":toilet,"ri.content":content,"ri.room.rid":rid}, function(result) {
		if(result.msg=="succ"){
			$('#myModal').modal('hide');
			$("#alertinfo").html("房间维护成功");
			$('#myinfo').modal('show');
			$("#closewin").bind("click",function(){
				window.location.href="../base/roominfo.action";
			});
		}else{
			$('#myModal').modal('hide');
			$("#alertinfo").html(result.msg);
			$('#myinfo').modal('show');
		}
	});
};

$(document).ready(function(){
	RoomInfoValidator.init();
});
